package com.cqie.campuscommon.result;


import com.cqie.campuscommon.enums.ResultCodeEnum;

/**
 * 接口返回实体
 *
 * @param <T>
 */
public final class Result<T> {
    private int code;
    private String msg;
    private T data;

    public Result() {
    }

    public Result(int code) {
        this.code = code;
        this.msg = "";
        this.data = null;
    }

    public Result(int code, String msg) {
        this.code = code;
        this.msg = msg;
        this.data = null;
    }

    public Result(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static Result Success(Object data) {
        return new Result(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMessage(), data);
    }

    public static Result Success(String message, Object data) {
        return new Result(ResultCodeEnum.SUCCESS.getCode(), message, data);
    }

    public static Result Success(Integer code, String msg) {
        return new Result(ResultCodeEnum.SUCCESS.getCode(), msg);
    }

    public static Result Success() {
        return Success("");
    }

    public static Result Failed(String msg) {
        return new Result(ResultCodeEnum.SYSTEM_EXCEPTION.getCode(), msg);
    }

    public static Result Failed() {
        return Failed("Failed");
    }

    public static Result Failed(int code, String msg) {
        return new Result(code, msg);
    }
    public  static  Result Failed(String message, Object data){
        return new Result(ResultCodeEnum.SYSTEM_EXCEPTION.getCode(), message, data);
    }

    public  static  Result success(int code , String msg){
        return new Result(code , msg);
    }

    public  static  Result error(int code , String msg){
        return new Result(code , msg);
    }
    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public boolean succeeded() {
        return getCode() == ResultCodeEnum.SUCCESS.getCode();
    }


    public boolean failed() {
        return getCode() != ResultCodeEnum.SUCCESS.getCode();
    }

}
